package com.yztc.love_travel.ui.mainservice.buy.presenter;

import android.util.Log;

import com.yztc.love_travel.bean.BuyingBean;
import com.yztc.love_travel.ui.mainservice.buy.model.BuyingModelImpl;
import com.yztc.love_travel.ui.mainservice.buy.model.IBuyingModel;
import com.yztc.love_travel.ui.mainservice.buy.view.BuyActivity;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/11/29.
 */

public class BuyingPresenterImpl implements IBuyingPresenter{

    private IBuyingModel mBuyingModel;
    private BuyActivity mBuyingView;

    public BuyingPresenterImpl(BuyActivity mBuyingView) {
        mBuyingModel = new BuyingModelImpl();
        this.mBuyingView = mBuyingView;
    }
    @Override
    public void getBuyingBean(String baseUrl, final Map<String, Object> params) {

        mBuyingModel.getBuyingBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BuyingBean>() {
                    @Override
                    public void onCompleted() {
                        mBuyingView.loadFinish();
                        Log.e("tag",params.toString());
                    }

                    @Override
                    public void onError(Throwable e) {
                        mBuyingView.loadError();

                    }

                    @Override
                    public void onNext(BuyingBean buyingBean) {
                        mBuyingView.showBuyingData(buyingBean);

                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mBuyingView.loadStart();
                    }
                });
    }
    }